home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Programming / AmigaE / Src / OOmodules / sort / address.e next >
Encoding:
Text File  |  1995-05-16  |  3.0 KB  |  158 lines

  1. OPT MODULE
  2. OPT EXPORT
  3. -> address.e by Trey Van Riper of the Cheese Olfactory Workshop
  4.  
  5. MODULE 'oomodules/sort/string','oomodules/sort'
  6.  
  7. -> address.e is a derived object from 'sortobj', but we'll sort to lname.
  8.  
  9. OBJECT address OF sort
  10.  lname:PTR TO string
  11.  fname:PTR TO string
  12.  street:PTR TO string
  13.  city:PTR TO string
  14.  phone:PTR TO string
  15. ENDOBJECT 
  16.  
  17. PROC size() OF address IS 48
  18.  
  19. PROC name() OF address IS 'Address'
  20.  
  21. -> We have much to initialize here.
  22.  
  23. PROC init() OF address
  24.  DEF tmp:PTR TO string
  25.  NEW tmp.new()
  26.  self.fname:=tmp
  27.  NEW tmp.new()
  28.  self.lname:=tmp
  29.  NEW tmp.new()
  30.  self.street:=tmp
  31.  NEW tmp.new()
  32.  self.city:=tmp
  33.  NEW tmp.new()
  34.  self.phone:=tmp
  35. ENDPROC
  36.  
  37. -> select() does tons-o-stuff for new()
  38.  
  39. PROC select(opt,i) OF address
  40.  DEF item
  41.  item:=ListItem(opt,i)
  42.  SELECT item
  43.   CASE "set"
  44.    INC i
  45.    self.set(ListItem(opt,i))
  46.   CASE "sfnm"
  47.    INC i
  48.    self.setFname(ListItem(opt,i))
  49.   CASE "slnm"
  50.    INC i
  51.    self.setLname(ListItem(opt,i))
  52.   CASE "scty"
  53.    INC i
  54.    self.setCity(ListItem(opt,i))
  55.   CASE "sstr"
  56.    INC i
  57.    self.setStreet(ListItem(opt,i))
  58.   CASE "sphn"
  59.    INC i
  60.    self.setPhone(ListItem(opt,i))
  61.  ENDSELECT
  62. ENDPROC i
  63.  
  64. -> Sets the first name.
  65.  
  66. PROC setFname(in) OF address
  67.  self.fname.set(in)
  68. ENDPROC
  69.  
  70. -> These two functions set the last name.
  71.  
  72. PROC set(in) OF address
  73.  self.setLname(in)
  74. ENDPROC
  75.  
  76. PROC setLname(in) OF address
  77.  self.lname.set(in)
  78. ENDPROC
  79.  
  80. -> Sets the Street address.
  81.  
  82. PROC setStreet(in) OF address
  83.  self.street.set(in)
  84. ENDPROC
  85.  
  86. -> Sets the City/State
  87.  
  88. PROC setCity(in) OF address
  89.  self.city.set(in)
  90. ENDPROC
  91.  
  92. -> Sets the phone #.
  93.  
  94. PROC setPhone(in) OF address
  95.  self.phone.set(in)
  96. ENDPROC
  97.  
  98. -> Most addresses are sorted to the last name (at least
  99. -> where I'm from), so the sorting is doing according to the
  100. -> last name.
  101.  
  102. PROC cmp(item:PTR TO address) OF address IS self.lname.cmp(item.lname)
  103.  
  104. -> This helps determine how much 'write' will require.
  105.  
  106. PROC length() OF address
  107.  DEF out
  108.  out := self.lname.length() + self.street.length() + self.city.length() +
  109.         self.phone.length() + self.fname.length()  + 40
  110. ENDPROC out
  111.  
  112. -> write() comes up with a text suitable to printing out an
  113. -> address.  Could be neater, but hey, it's only an example.
  114. -> This, of course, gives a String output.
  115.  
  116. PROC write() OF address
  117.  DEF out:PTR TO string
  118.  NEW out.new()
  119.  out.cat('Name:   "')
  120.  out.catString(self.lname)
  121.  out.cat(', ')
  122.  out.catString(self.fname)
  123.  out.cat('"\nStreet: ')
  124.  out.catString(self.street)
  125.  out.cat('\nCity:   ')
  126.  out.catString(self.city)
  127.  out.cat('\nPhone:  ')
  128.  out.catString(self.phone)
  129.  out.cat('\n')
  130.  /*
  131.  StringF(out,'Name: "\s, \s"\nStreet: \s\nCity: \s\nPhone: \s\n',self.lname.write(),
  132.                                   self.fname.write(),
  133.                                   self.street.write(),
  134.                                  self.city.write(),
  135.                                  self.phone.write())
  136.   */
  137. ENDPROC out
  138.  
  139. -> This is a unique id # for address: "addr"
  140.  
  141. PROC id() OF address IS "addr"
  142.  
  143. -> Tons-o-stuff to deallocate.
  144.  
  145. PROC end() OF address
  146.  DEF tmp:PTR TO string
  147.  tmp:=self.street
  148.  END tmp
  149.  tmp:=self.city
  150.  END tmp
  151.  tmp:=self.phone
  152.  END tmp
  153.  tmp:=self.lname
  154.  END tmp
  155.  tmp:=self.fname
  156.  END tmp
  157. ENDPROC
  158.